/**
 * Copyright (c) 2011 Nokia Corporation.
 */

#include <QtDeclarative/QDeclarativeView>
#include <QtGui/QApplication>
#include <QtGui/QDesktopWidget>
#include <QGraphicsObject>
#ifndef QT_NO_OPENGL
#include <QGLWidget>
#endif

#include "componentloader.h"

const int SPLASH_SCREEN_DELAY = 1000;

int main(int argc, char* argv[])
{
    QApplication a(argc, argv);

    QDeclarativeView view;
    #ifndef QT_NO_OPENGL
    // Use QGLWidget to get the OpenGL support if available
    QGLFormat format = QGLFormat::defaultFormat();
    format.setSampleBuffers(false);

    QGLWidget *glWidget = new QGLWidget(format);
    glWidget->setAutoFillBackground(false);
    view.setViewport(glWidget);  // ownership of glWidget is taken
    #endif
    // The main QML file can be loaded from QRC when Qt Quick components 1.1
    // will be published
    // (see https://bugreports.qt.nokia.com//browse/QTCOMPONENTS-858)
//    view.setSource(QUrl("qrc:/qml/SplashScreen.qml"));
    view.setSource(QUrl::fromLocalFile("qml/SplashScreen.qml"));
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);

    QObject::connect((QObject*)view.engine(), SIGNAL(quit()),
                     &a, SLOT(quit()));

    // Ensure that the size of the view is calculated correctly.
    view.setGeometry(QApplication::desktop()->screenGeometry());
    view.showFullScreen();

    ComponentLoader componentLoader(view);
    componentLoader.load(SPLASH_SCREEN_DELAY);

    return a.exec();
}
